package com.example.a10928.weifriend.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.a10928.weifriend.R;


public class TaskListItemLayout extends ConstraintLayout {

    TextView task_tv_name, task_state, task_tv_price, task_tv_size, task_check_tv;
    ImageView task_iv;

    public TaskListItemLayout(Context context) {
        super(context);
    }

    public TaskListItemLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        ConstraintLayout.inflate(context, R.layout.layout_task_list_item, this);
        task_iv = (ImageView) findViewById(R.id.task_iv);
        task_tv_name = (TextView) findViewById(R.id.task_tv_name);
        task_state = (TextView) findViewById(R.id.task_state);
        task_tv_price = (TextView) findViewById(R.id.task_tv_price);
        task_tv_size = (TextView) findViewById(R.id.task_tv_size);
        task_check_tv = (TextView) findViewById(R.id.task_check_tv);
        task_tv_name.setSelected(true);


        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TaskListItemLayout);
        int drawable = typedArray.getResourceId(R.styleable.TaskListItemLayout_TaskListItemLayout_iv, R.drawable.home_page);
        String title = typedArray.getString(R.styleable.TaskListItemLayout_TaskListItemLayout_name);
        String price = typedArray.getString(R.styleable.TaskListItemLayout_TaskListItemLayout_price);
        String state = typedArray.getString(R.styleable.TaskListItemLayout_TaskListItemLayout_state);
        if (title == null) {
            title = "";
        }
        if (price == null) {
            price = "";
        }
        if (state == null) {
            state = "";
        }

        typedArray.recycle();//释放资源

        task_iv.setImageResource(drawable);
        task_tv_name.setText(title);
        task_state.setText(state);
        task_tv_price.setText(price);


    }

    public void setIv(int res) {
        task_iv.setImageResource(res);
    }

    public void setName(String name) {
        task_tv_name.setText(name);
    }

    public void setState(String state) {
        task_state.setText(state);
    }

    public void setPrice(String price) {
        task_tv_price.setText("￥ " + price);
    }

    public void setTask_tv_size(Boolean is) {
        if (is) {
            task_tv_size.setVisibility(View.VISIBLE);
        }else{
            task_tv_size.setVisibility(View.GONE);
        }
    }

    public void setTask_check_tv(Boolean is) {
        if (is) {
            task_check_tv.setVisibility(View.VISIBLE);
        }else{
            task_check_tv.setVisibility(View.GONE);
        }
    }


}